package com.syx.extensiondemo.Config;

import com.rabbitmq.client.AMQP;
import com.syx.extensiondemo.Constant.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
public class DlConfig {

    @Bean("normalQueue")
    public Queue normalQueue(){
        //指定死信队列
        return QueueBuilder.durable(Constants.NORMAL_QUEUE)
                .deadLetterExchange(Constants.DL_EXCHANGE)
                .deadLetterRoutingKey("dl")
                .ttl(10000)
                //设置最大长度
                .maxLength(10)
                .build();

    }

    @Bean("normalExchange")
    public DirectExchange normalExchange(){
        return ExchangeBuilder.directExchange(Constants.NORMAL_EXCHANGE).build();

    }


    @Bean("normalBinding")
    public Binding normalBinding(@Qualifier("normalQueue") Queue queue,@Qualifier("normalExchange") DirectExchange normalExchange){
        return BindingBuilder.bind(queue).to(normalExchange).with("normal");

    }


    //死信交换机和死信队列
    @Bean("DlQueue")
    public Queue DlQueue(){
        return QueueBuilder.durable(Constants.DL_QUEUE).build();

    }

    @Bean("DlExchange")
    public DirectExchange DlExchange(){
        return ExchangeBuilder.directExchange(Constants.DL_EXCHANGE).build();

    }


    @Bean("dlBinding")
    public Binding dlBinding(@Qualifier("DlQueue") Queue queue,@Qualifier("DlExchange") DirectExchange DlExchange){
        return BindingBuilder.bind(queue).to(DlExchange).with("dl");

    }
}
